package net.cdsunrise.com.common.grantedauthority;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.Assert;

/**
 * @author: LiuWei
 * @date: Create in 15:58 2018/05/14
 */
public class SpringGrantedAuthority implements GrantedAuthority {
    private static final long serialVersionUID = 410L;
    private final String role;

    private SpringGrantedAuthority() {
        role = "";
    }

    public SpringGrantedAuthority(String role) {
        Assert.hasText(role, "A granted authority textual representation is required");
        this.role = role;
    }

    @Override
    public String getAuthority() {
        return this.role;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        } else {
            return obj instanceof SpringGrantedAuthority ? this.role.equals(((SpringGrantedAuthority) obj).role) : false;
        }
    }

    @Override
    public int hashCode() {
        return this.role.hashCode();
    }

    @Override
    public String toString() {
        return this.role;
    }
}
